package com.imooc.springboot.dubbo.nilinili.provider.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.imooc.springboot.dubbo.nilinili.entity.dto.CategoryDTO;
import com.imooc.springboot.dubbo.nilinili.provider.entity.po.CategoryPO;
import com.imooc.springboot.dubbo.nilinili.provider.mapper.CategoryMapper;
import com.imooc.springboot.dubbo.nilinili.res.CodeEnum;
import com.imooc.springboot.dubbo.nilinili.res.ResultFactory;
import com.imooc.springboot.dubbo.nilinili.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import static com.imooc.springboot.dubbo.nilinili.provider.utils.BeanCopierUtil.copyObjects;

@Service(interfaceClass = CategoryService.class)
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public String SelectAllSonsByName(String name) {
        Integer integer = categoryMapper.selectIdByName(name);
        List<CategoryPO> categoryPO = categoryMapper.selectAllSonsById(integer);
        List<CategoryDTO> categoryDTOS = copyObjects(categoryPO, CategoryDTO.class);
        return ResultFactory.createResult(CodeEnum.SUCCESS,"success",categoryDTOS);
    }

    @Override
    public Integer selectIdByName(String name) {
        return categoryMapper.selectIdByName(name);
    }


}

